<?php

namespace app\admin\validate;
//TODO:删除use示例
use app\common\model\Config as ConfigModel;

class Login extends AdminBase
{

    // 验证规则
    protected $rule = [
        'username'       => 'require',
        'password'       => 'require',
    ];

    // 验证提示
    protected $message = [
        'username'       => '缺少username参数',
        'password'       => '缺少password参数',
    ];

    // 应用场景
    protected $scene = [
        'login'          => ['username','password'],
    ];

    //查询数据重复
    public function checkExist($value, $rule, $data = [], $field = ''){

        if ($field == 'name') {
            $where[] = ['name','=',$value];
            /*$where[] = ['module','=',$data['module']];
            $where[] = ['type','=',$data['type']];*/
            isset($data['id']) &&  $where[] = ['id','<>',$data['id']];
            $total =  ConfigModel::where($where)->count();
            if ($total > 0) {
                return '数据已存在';
            }
        }
        return true;
    }
}